#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e3 + 10;
ll a[N][N];
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
void solve()
{
    ll n;
    cin >> n;
    for (ll i = 1; i <= n;i++)
    {
        for (ll j = 1; j <= i;j++)
        {
            cin >> a[i][j];
        }
    }

    for (ll i = 1; i < n; i++)
    {
        for (ll j = 1; j <= i; j++)
        {
            if(a[i][j]>a[i+1][j]||a[i][j]>a[i+1][j+1])
            {
                no;
                return;
            }
        }
    }
    yes;
}
int main()
{
    ll t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}